﻿<UserControl x:Class="EasyInvoice.WPF.Content.InvoiceListNew"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:mui="http://firstfloorsoftware.com/ModernUI"
			 xmlns:vm="clr-namespace:EasyInvoice.WPF.ViewModel"
             xmlns:common="clr-namespace:EasyInvoice.WPF.Common"
			 xmlns:app="clr-namespace:EasyInvoice.WPF"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:gl="clr-namespace:System.Globalization;assembly=mscorlib"
			 >
    <UserControl.Resources>
        <common:VisibleConverter x:Key="visibleConverter"/>
    </UserControl.Resources>
    <UserControl.DataContext>
        <vm:InvoiceListNewViewModel/>
    </UserControl.DataContext>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Text="Invoice List " Style="{StaticResource Heading1}" Margin="0,0,0,8" />
        <StackPanel Grid.Row="1" VerticalAlignment="Center" Margin=" 0,-8,0,0">
            <DockPanel DockPanel.Dock="Right" HorizontalAlignment="Right">
                <TextBlock Text="filters:" Margin="8,0,0,0" VerticalAlignment="Center"/>
                <TextBlock Text="number" Margin="8,0,3,0" VerticalAlignment="Center"/>
                <TextBox Width="50" Text="{Binding Number,Mode=TwoWay}"/>
                <TextBlock Text="date between" Margin="8,0,3,0" VerticalAlignment="Center"/>
                <DatePicker Text="{Binding StartDate,Mode=TwoWay}"/>
                <Separator/>
                <DatePicker Text="{Binding EndDate,Mode=TwoWay}"/>
                <TextBlock Text="to" Margin="8,0,3,0" VerticalAlignment="Center"/>
                <ComboBox Width="100" ItemsSource="{Binding Source={StaticResource clientsComboDataSource}}"  DisplayMemberPath="Name" SelectedItem="{Binding FilterClient,Mode=TwoWay}"/>
                <TextBlock Text="from" Margin="8,0,3,0" VerticalAlignment="Center"/>
                <ComboBox Width="100" ItemsSource="{Binding Source={StaticResource sellersComboDataSource}}"  DisplayMemberPath="Name" SelectedItem="{Binding FilterSeller,Mode=TwoWay}"/>
                <mui:ModernButton EllipseDiameter="24" IconWidth="14" IconHeight="14" Margin="8,0,3,0"
								x:Name="searchModernButton"
								IconData="M 34.8333,61.75L 34.8333,42.75L 19,20.5833L 57,20.5833L 41.1667,42.75L 41.1667,58.5833L 34.8333,61.75 Z "
								Command="{Binding RefreshCommand}"
								ToolTip="filter invoices"/>
            </DockPanel>
            <!--<DockPanel DockPanel.Dock="Left" HorizontalAlignment="Left">
                <mui:ModernButton  EllipseDiameter="24" IconWidth="14" IconHeight="14"
								x:Name="addModernButton"
								IconData="M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "
								Command="{Binding ShowAddCommand}"
								ToolTip="add invoice"/>
                <mui:ModernButton EllipseDiameter="24" IconWidth="14" IconHeight="14"
								x:Name="deleteModernButton"
								IconData="M 25.3333,23.75L 50.6667,23.75C 51.5411,23.75 51.8541,27.3125 51.8541,27.3125L 24.1458,27.3125C 24.1458,27.3125 24.4589,23.75 25.3333,23.75 Z M 35.625,19.7917L 40.375,19.7917C 40.8122,19.7917 41.9583,20.9378 41.9583,21.375C 41.9583,21.8122 40.8122,22.9584 40.375,22.9584L 35.625,22.9584C 35.1878,22.9584 34.0416,21.8122 34.0416,21.375C 34.0416,20.9378 35.1878,19.7917 35.625,19.7917 Z M 27.7083,28.5L 48.2916,28.5C 49.1661,28.5 49.875,29.2089 49.875,30.0834L 48.2916,53.8334C 48.2916,54.7078 47.5828,55.4167 46.7083,55.4167L 29.2917,55.4167C 28.4172,55.4167 27.7083,54.7078 27.7083,53.8334L 26.125,30.0834C 26.125,29.2089 26.8339,28.5 27.7083,28.5 Z M 30.0833,31.6667L 30.4792,52.25L 33.25,52.25L 32.8542,31.6667L 30.0833,31.6667 Z M 36.4167,31.6667L 36.4167,52.25L 39.5833,52.25L 39.5833,31.6667L 36.4167,31.6667 Z M 43.1458,31.6667L 42.75,52.25L 45.5208,52.25L 45.9167,31.6667L 43.1458,31.6667 Z "
								Command="{Binding ShowDeleteCommand}"
								ToolTip="delete invoice"/>
                <mui:ModernButton EllipseDiameter="24" IconWidth="14" IconHeight="14"
								x:Name="refreshModernButton"
								IconData="M 38,20.5833C 42.9908,20.5833 47.4912,22.6825 50.6667,26.046L 50.6667,17.4167L 55.4166,22.1667L 55.4167,34.8333L 42.75,34.8333L 38,30.0833L 46.8512,30.0833C 44.6768,27.6539 41.517,26.125 38,26.125C 31.9785,26.125 27.0037,30.6068 26.2296,36.4167L 20.6543,36.4167C 21.4543,27.5397 28.9148,20.5833 38,20.5833 Z M 38,49.875C 44.0215,49.875 48.9963,45.3932 49.7703,39.5833L 55.3457,39.5833C 54.5457,48.4603 47.0852,55.4167 38,55.4167C 33.0092,55.4167 28.5088,53.3175 25.3333,49.954L 25.3333,58.5833L 20.5833,53.8333L 20.5833,41.1667L 33.25,41.1667L 38,45.9167L 29.1487,45.9167C 31.3231,48.3461 34.483,49.875 38,49.875 Z "
								Command="{Binding RefreshCommand}"
								ToolTip="refresh"/>
                <mui:ModernButton EllipseDiameter="24" IconWidth="14" IconHeight="14"
								x:Name="printModernButton"
								IconData="M 36.3069,56.4426C 34.0702,58.5195 30.0833,62.75 32.7881,62.0168C 37.1473,59.3959 39.8714,50.9915 42.094,45.3712C 39.5065,39.6288 42.0013,35.1728 43.9683,35.0417C 46.3648,34.8819 46.9895,39.4244 46.9895,39.4244C 46.9895,39.4244 44.3333,37.4167 43.9284,36.1928C 43.4703,36.3073 42.9792,40.0292 44.3333,44.1458C 45.9167,42.1667 46.7083,40.1875 46.7083,40.1875C 46.7083,40.1875 48.6875,42.1667 45.7172,45.205C 46.2479,46.3813 49.1405,51.1227 50.4509,51.9807C 58.75,49.75 59.1457,54.1261 59.1457,54.1261C 57.8643,52.9561 55.0287,52.8353 51.8787,53.1741C 55.8527,55.2618 59.2167,54.5712 59.2167,54.5712C 59.2167,56.206 53.8333,58 49.8596,54.2353C 45.6983,54.888 41.4481,56.8904 39.7663,57.3957C 35.2719,65.2481 30.3574,64.6256 29.6875,62.75C 28.5,59.5833 36.3069,56.4426 36.3069,56.4426 Z M 43.9949,46.8185L 41.0559,54.9219C 42.7814,54.4274 44.6885,53.4792 48.1081,52.8076C 47,52 46,51 43.9949,46.8185 Z M 20,17L 43.25,17L 56,29.75L 56,50L 52,50.25L 52,34L 39,34L 39,21L 24,21L 24,55L 34.5,55L 30,59L 20,59L 20,17 Z M 40,59L 40,58.5L 49,55.5L 56,59L 40,59 Z M 43,22.25L 43,30L 50.75,30L 43,22.25 Z "
								Command="{Binding PrintCommand}"
								ToolTip="export invoice to pdf"/>
               
            </DockPanel>-->
        </StackPanel>
        <DataGrid ItemsSource="{Binding Invoices}" Grid.Row="2" SelectedItem="{ Binding SelectedInvoice}" AutoGenerateColumns="False" 
                  CanUserAddRows="{Binding CanAddInvoices, UpdateSourceTrigger=PropertyChanged}" 
                  CanUserDeleteRows="{Binding CanDeleteInvoices,UpdateSourceTrigger=PropertyChanged}"
                  IsReadOnly="{Binding CanEditInvoices, UpdateSourceTrigger=PropertyChanged}"
                  RowDetailsVisibilityMode="Collapsed" SelectionMode="Single">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="RowEditEnding">
                    <i:InvokeCommandAction Command="{Binding ShowSaveCommand}"
                            CommandParameter="{Binding}"/>
                    <!--Command="{Binding ShowSaveCommand}"/>-->
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.InputBindings>
                <KeyBinding Key="Delete" Command="{Binding ShowDeleteCommand}" />
            </DataGrid.InputBindings>
            <DataGrid.Columns>
                <mui:DataGridTextColumn Header="Number" Width="*"
                                        Binding="{Binding Number,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
                <DataGridTemplateColumn Header="Date" Width="*">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock  Text="{Binding Date, StringFormat='d', ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
                                        VerticalAlignment="Center"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <DatePicker Text="{Binding Date,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <mui:DataGridComboBoxColumn Header="Client" Width="*"
                                            ItemsSource="{Binding Source={StaticResource clientsComboDataSource}}" 
                                            SelectedItemBinding="{Binding Client,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" 
                                            DisplayMemberPath="Name"
                                            />
                <mui:DataGridComboBoxColumn Header="Seller" Width="*"
                                            ItemsSource="{Binding Source={StaticResource sellersComboDataSource}}" 
                                            SelectedItemBinding="{Binding Seller,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                            DisplayMemberPath="Name"/>
                <mui:DataGridTextColumn Header="Total Amount" IsReadOnly="True"
                                                    Binding="{Binding TotalAmount, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat={}{0:C}}" >
                    <mui:DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextAlignment" Value="Right" />
                        </Style>
                    </mui:DataGridTextColumn.ElementStyle>
                </mui:DataGridTextColumn>
                <DataGridTextColumn Header="Details" Visibility="Hidden"
                                    Binding="{Binding Details,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>

                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <mui:ModernButton 
								x:Name="printModernButton"
								IconData="M 36.3069,56.4426C 34.0702,58.5195 30.0833,62.75 32.7881,62.0168C 37.1473,59.3959 39.8714,50.9915 42.094,45.3712C 39.5065,39.6288 42.0013,35.1728 43.9683,35.0417C 46.3648,34.8819 46.9895,39.4244 46.9895,39.4244C 46.9895,39.4244 44.3333,37.4167 43.9284,36.1928C 43.4703,36.3073 42.9792,40.0292 44.3333,44.1458C 45.9167,42.1667 46.7083,40.1875 46.7083,40.1875C 46.7083,40.1875 48.6875,42.1667 45.7172,45.205C 46.2479,46.3813 49.1405,51.1227 50.4509,51.9807C 58.75,49.75 59.1457,54.1261 59.1457,54.1261C 57.8643,52.9561 55.0287,52.8353 51.8787,53.1741C 55.8527,55.2618 59.2167,54.5712 59.2167,54.5712C 59.2167,56.206 53.8333,58 49.8596,54.2353C 45.6983,54.888 41.4481,56.8904 39.7663,57.3957C 35.2719,65.2481 30.3574,64.6256 29.6875,62.75C 28.5,59.5833 36.3069,56.4426 36.3069,56.4426 Z M 43.9949,46.8185L 41.0559,54.9219C 42.7814,54.4274 44.6885,53.4792 48.1081,52.8076C 47,52 46,51 43.9949,46.8185 Z M 20,17L 43.25,17L 56,29.75L 56,50L 52,50.25L 52,34L 39,34L 39,21L 24,21L 24,55L 34.5,55L 30,59L 20,59L 20,17 Z M 40,59L 40,58.5L 49,55.5L 56,59L 40,59 Z M 43,22.25L 43,30L 50.75,30L 43,22.25 Z "
								Command="{Binding PrintCommand}"
								ToolTip="export invoice to pdf"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <DataGrid ItemsSource="{Binding Details}" AutoGenerateColumns="False" >
                        <DataGrid.Columns>
                            <mui:DataGridTextColumn Header="Description" MinWidth="300" 
                                                    Binding="{Binding Description, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"/>
                            <mui:DataGridTextColumn Header="Unit Price" 
                                                    Binding="{Binding Price,UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat={}{0:C}}">
                                <mui:DataGridTextColumn.ElementStyle>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="TextAlignment" Value="Right" />
                                    </Style>
                                </mui:DataGridTextColumn.ElementStyle>
                                <mui:DataGridTextColumn.EditingElementStyle>
                                    <Style TargetType="TextBox">
                                        <Setter Property="TextAlignment" Value="Right" />
                                    </Style>
                                </mui:DataGridTextColumn.EditingElementStyle>
                            </mui:DataGridTextColumn>
                            <mui:DataGridTextColumn Header="Quantity" 
                                                    Binding="{Binding Units, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
                                <mui:DataGridTextColumn.ElementStyle>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="TextAlignment" Value="Right" />
                                    </Style>
                                </mui:DataGridTextColumn.ElementStyle>
                                <mui:DataGridTextColumn.EditingElementStyle>
                                    <Style TargetType="TextBox">
                                        <Setter Property="TextAlignment" Value="Right" />
                                    </Style>
                                </mui:DataGridTextColumn.EditingElementStyle>
                            </mui:DataGridTextColumn>
                            <mui:DataGridTextColumn Header="Amount" IsReadOnly="True"
                                                    Binding="{Binding Value, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, StringFormat={}{0:C}}" >
                                <mui:DataGridTextColumn.ElementStyle>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="TextAlignment" Value="Right" />
                                    </Style>
                                </mui:DataGridTextColumn.ElementStyle>
                            </mui:DataGridTextColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
            <DataGrid.RowHeaderTemplate>  
            <DataTemplate>
                    <ToggleButton Padding="0" Width="14" Height="14"  
                                  BorderThickness="0" 
                                  VerticalContentAlignment="Top" Background="Transparent"
                                  Margin="1,4"
                    IsChecked="{Binding Converter={StaticResource visibleConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=DetailsVisibility}" >
                      
                        <Canvas   Margin="0" 
                                  Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}, Path=Width}"
                                  Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}, Path=Height}">
                            <Path Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}, Path=Foreground}" 
                                  Stretch="Fill"
                                  Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}, Path=Width}"
                                  Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToggleButton}}, Path=Height}"
                                  >
                                <Path.Style>
                                    <Style TargetType="Path">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="false">
                                                <Setter Property="Path.Data" Value="M 20,20L 56,20L 56,56L 20,56L 20,20 Z M 24,24L 24,52L 52,52L 52,24L 24,24 Z M 31,36L 36,36L 36,31L 40,31L 40,36L 45,36L 45,40L 40,40L 40,45L 36,45L 36,40L 31,40L 31,36 Z " />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="true">
                                                <Setter Property="Path.Data" Value="M 20,20L 56,20L 56,56L 20,56L 20,20 Z M 24,24L 24,52L 52,52L 52,24L 24,24 Z M 31,36L 45,36L 45,40L 31,40L 31,36 Z " />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Path.Style>
                            </Path>
                        </Canvas>
                    </ToggleButton>
                </DataTemplate>
            </DataGrid.RowHeaderTemplate>
        </DataGrid>



    </Grid>
</UserControl>
